typeAsDrawable

fun Context.typeAsDrawable(@DrawableOrDrawableRes drawableOrDrawableRes: Any?): Drawable?

Parses the received data type drawableOrDrawableRes and always returns a Drawable.

  • If the data type is null, it returns null.

  • If the data type is a Drawable, it returns it as is, without processing.

  • If the data type is an integer, it is assumed to be a resource ID, so the Drawable is obtained from resources and returned. If the resource does not exist, it throws an exception.

  • For any another data type, it throws an exception, since the data type cannot be parse as a Drawable.

The parameter and return value can be null according to the definition of AppCompatResources.getDrawable()